#ifndef ODN_OGREINPUTDEVICE_H
#define ODN_OGREINPUTDEVICE_H

#include <ogre\Ogre.h>
#include <ogre\OgreKeyEvent.h>
#include <ogre\OgreMouseEvent.h>
#include <ogre\OgreEventListeners.h>

#include "ODN_InputDevice.h"
#include "ODN_Maths.h"

namespace ouden {

//Abstract input device interface
class COgreInputDevice : public IInputDevice, public Ogre::KeyListener, public Ogre::MouseListener, public Ogre::MouseMotionListener
{
	public:
		
		COgreInputDevice(Ogre::EventProcessor* pEventProcessor);
		virtual ~COgreInputDevice();
		
		//Captures the state of input devices
		virtual void captureInput() 				{ m_pInputReader->capture(); }
		
		virtual bool isKeyDown(KeyCode iKey) 		{ return m_pInputReader->isKeyDown(Ogre::KeyCode(iKey)); }
		virtual Vector getMousePos() 				{ return Vector(m_pInputReader->getMouseAbsX(), 
																	m_pInputReader->getMouseAbsY(), 0); }
		virtual Vector getMouseRel() 				{ return Vector(m_pInputReader->getMouseRelX(), 
																	m_pInputReader->getMouseRelY(), 0); }
		virtual bool isMouseButtonDown(MouseButton iButton) 		{ return m_pInputReader->getMouseButton(iButton); }
		//TODO: Add mouse displacement vector and more
		
		
		
		//Ogre KeyListener events redirect to onKeyDown and onKeyUp events in registered InputReceivers
		virtual void keyClicked (Ogre::KeyEvent *e) 		{ informKeyPress(e->getKey()); }
		virtual void keyPressed (Ogre::KeyEvent *e) 		{ informKeyDown(e->getKey()); }
		virtual void keyReleased (Ogre::KeyEvent *e) 		{ informKeyUp(e->getKey()); }
		
		virtual void mouseMoved (Ogre::MouseEvent *e) 			{ informMouseMove( Vector(e->getX(), e->getY(), e->getZ()), e->getModifiers() ); }
		virtual void mouseDragged (Ogre::MouseEvent *e) 		{ informMouseMove( Vector(e->getX(), e->getY(), e->getZ()), e->getModifiers() ); }
		
		//Ogre MouseListener events redirect to onMouseDown and onMouseUp events in registered InputReceivers
		virtual void mouseClicked (Ogre::MouseEvent *e) 		{ informMouseButtonPress( Vector(e->getX(), e->getY(), e->getZ()), e->getButtonID() ); }
		virtual void mousePressed (Ogre::MouseEvent *e) 		{ informMouseButtonUp( Vector(e->getX(), e->getY(), e->getZ()), e->getButtonID() ); }
		virtual void mouseReleased (Ogre::MouseEvent *e)	 	{ informMouseButtonDown( Vector(e->getX(), e->getY(), e->getZ()), e->getButtonID() ); }
		virtual void mouseEntered (Ogre::MouseEvent *e) 		{}
		virtual void mouseExited (Ogre::MouseEvent *e) 			{}
		
	protected:
		
	private:
		
		Ogre::InputReader* 		m_pInputReader; 		//Object to get input
		
};

} //namespace ouden

#endif //ODN_OGREINPUTDEVICE_H
